package controllayer;

import modellayer.Customer;
import dblayer.CustomerDB;


/**
 * The customerCTR class to handle customer information
 * @author Allan Eriksen, Andreas Rye, Casper Madsen, Christian Stidsborg, Stefan Bols
 */
public class CustomerCTR
{
	private CustomerDB cDB;
	
	/**
	 * CustomerCTR Fields
	 * @param cDB
	 */
	
	/**
	 * Constructor for the CustomerCTR class
	 */
	public CustomerCTR()
	{
		 cDB = new CustomerDB();
	}
	
	/**
	 * get method to get a customer from the database using customerNo
	 * @param customerNo
	 * @return c
	 */
	public Customer getCustomerByCustomerNo(int customerNo)
	{
		Customer c = null;
		
		if (cDB.findCustomerByCustomerNo(customerNo) != null)
		{
			c = cDB.findCustomerByCustomerNo(customerNo);
		}
		
		return c;
	}
	
	/**
	 * get method to get a customer from the database using phonenumber
	 * @param phonenumber
	 * @return c
	 */
	public Customer getCustomerByPhone(String phonenumber)
	{
		Customer c = null;
		
		if (cDB.findCustomerByPhonenumber(phonenumber) != null)
		{
			c = cDB.findCustomerByPhonenumber(phonenumber);
		}
		
		return c;
	}
	
	/**
	 * insert method to insert a customer in to the database
	 * @param c
	 */
	public void insertCustomer(Customer c) throws Exception
	{
		cDB.insertCustomer(c);
	}
}
